﻿Public Class MASCLINIC
    Private CLINIC = Nothing
    Private CLINICCODE = Nothing
    Private CLINICNAME = Nothing
    Private FMED = Nothing
    Private F_SEQ = Nothing
    Private F_WRD = Nothing
    Private COLOR = Nothing
    Private ClinicStatus = Nothing
    'Private selectMasprename = "SELECT PRENAME, FTPRENAME, FEPRENAME, STPRENAME, SEPRENAME, SEX, convert(bit, [STATUS]) FROM MASPRENAME"
    Private selectMasClinic = "SELECT `clinic` as 'รหัสหน่วยงาน',`cliniccode` as 'ชื่อย่อหน่วยงาน',`clinicname` as 'ชื่อหน่วยงาน',`fmed`,`f_seq`,`f_wrd`,`color` as 'สี',`status` as 'สถานะการเปิดใช้งาน' FROM masclinic "
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property COLOR_ As String
        Get
            Return COLOR
        End Get
        Set(value As String)
            COLOR = value
        End Set
    End Property

    Property F_WRD_ As Boolean
        Get
            Return F_WRD
        End Get
        Set(value As Boolean)
            If value = True Then
                F_WRD = 1
            Else
                F_WRD = 0
            End If
        End Set
    End Property

    Property F_SEQ_ As Boolean
        Get
            Return F_SEQ
        End Get
        Set(value As Boolean)
            If value = True Then
                F_SEQ = 1
            Else
                F_SEQ = 0
            End If
        End Set
    End Property

    Property FMED_ As Boolean
        Get
            Return FMED
        End Get
        Set(value As Boolean)
            If value = True Then
                FMED = 1
            Else
                FMED = 0
            End If
        End Set
    End Property

    Property CLINICNAME_ As String
        Get
            Return CLINICNAME
        End Get
        Set(value As String)
            CLINICNAME = value
        End Set
    End Property

    Property CLINICCODE_ As String
        Get
            Return CLINICCODE
        End Get
        Set(value As String)
            CLINICCODE = value
        End Set
    End Property

    Property CLINIC_ As Integer
        Get
            Return CLINIC
        End Get
        Set(value As Integer)
            CLINIC = value
        End Set
    End Property

    Property ClinicStatus_ As Boolean
        Get
            Return ClinicStatus
        End Get
        Set(value As Boolean)
            If value = True Then
                ClinicStatus = 1
            Else
                ClinicStatus = 0
            End If
        End Set
    End Property

    Property selectMasClinic_ As String
        Get
            Return selectMasClinic
        End Get
        Set(value As String)

        End Set
    End Property

    'Public Function SEXCombobox() As DataTable
    '    connectlocal = conlocal.NewConnection()
    '    Return connectlocal.GetTable("SELECT SEX, SEXDESC FROM MASSEX WHERE [STATUS] = 1")
    'End Function

    Public Sub insertMasClinicData()
        If CLINICCODE <> "" Then
            If TypeOf CLINICCODE Is String Then
                If connect.GetTable("SELECT `cliniccode` FROM masclinic WHERE `cliniccode` = '" & CLINICCODE & "'").Rows.Count > 0 Then
                    MsgBox("มีข้อมูลนี้อยู่ในระบบแล้ว")
                Else
                    Try
                        connect = CONDB.NewConnection()
                        'connectlocal = conlocal.NewConnection()
                        Dim VSID As Integer
                        VSID = connect.ExecuteScalar("INSERT INTO masclinic (`clinic`,`cliniccode`,`clinicname`,`fmed`,`f_seq`,`f_wrd`,`color`,`status`) VALUES ('" & CLINIC & "','" & CLINICCODE & "','" & CLINICNAME & "','" & FMED & "','" & F_SEQ & "', " & F_WRD & "'," & COLOR & "','" & ClinicStatus & "'); SELECT LAST_INSERT_ID();")
                        'connectlocal.ExecuteNonQuery("INSERT INTO MASPENNAME (PENNAME,PENLNAME, SEX, STATUS) VALUES ('" & PENNAME & "','" & PENLNAME & "','" & SEX & "', '" & pennameStatus & "')")
                        MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว")
                    Catch ex As Exception
                        MsgBox("มีข้อมูลนี้อยู่ในระบบอยู่แล้ว" & vbCrLf & ex.Message)
                    End Try
                    connect.Dispose()
                End If
            Else
                MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
            End If
        Else
            MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วน")
        End If
    End Sub

    Public Sub editMasClinicData()
        If CLINIC > 0 And CLINICCODE <> "" Then
            If TypeOf CLINICCODE Is String Then
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    Dim sql As String
                    sql = ("UPDATE masclinic SET `cliniccode` = '" & CLINICCODE & "', `clinicname` = '" & CLINICNAME & "' , `fmed` = '" & FMED & "',`f_seq` = '" & F_SEQ & "',`f_wrd` = '" & F_WRD & "',`color` = '" & COLOR & "', `status` = '" & ClinicStatus & "' WHERE `clinic` = '" & CLINIC & "'")
                    connect.ExecuteNonQuery(sql)
                    'connectlocal.ExecuteNonQuery("UPDATE MASPENNAME SET PENNAME = '" & PENNAME & "',PENLNAME = '" & PENLNAME & "' , SEX = '" & SEX & "', STATUS = '" & pennameStatus & "' WHERE PRENAME = '" & pennameID & "'")
                    MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox("มีข้อมูลนี้อยู่ในระบบแล้ว" & vbCrLf & ex.Message)
                End Try
                connect.Dispose()
            Else
                MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
            End If
        Else
            MsgBox("ท่านต้องทำการกรอกข้อมูลให้ครบถ้วน")
        End If
    End Sub
End Class
